<?php
/**
* phpCan - http://idc.anavallasuiza.com/
*
* phpCan is released under the GNU Affero GPL version 3
*
* More information at license.txt
*/

namespace data\formats;

defined('ANS') or die();

class Boolean extends Formats implements iFormats {
	var $format = 'boolean';

	public function check ($value) {
		$this->error = array();

		if (strlen($value['']) > 1) {
			$value[''] = intval($value[''][0]);
		}

		return $this->validate($value);
	}

	public function valueDB (\data\Data $Data, $value, $language = '', $id = 0) {
		return array(
			'' => $value[''] ? 1 : 0
		);
	}

	public function settings ($settings) {
		$this->settings = $this->setSettings($settings, array(
			'' => array(
				'db_type' => 'tinyint',
				'db_unsigned' => true,

				'length_max' => 1,
			)
		));

		return $this->settings;
	}
}
?>